import axios from 'axios'
import qs from 'qs'

let instance = axios.create({
    baseURL: 'http://localhost:2345/',
    timeout: 5000,
});

instance.interceptors.request.use(config => {
    if (config.method == 'post') {
        config.data = qs.stringify({ ...config.data })
    } else {
        config.params = { ...config.params }
    }
    config.headers['Content-Type'] = 'application/X-www-form-urlencoded';
    return config
},
    err => {
        // return Promise reject(err)
        return Promise.reject(err)
    }
)

instance.interceptors.response.use(
    response => {
        console.log(response.data)
        return response.data
    },
    error => {
        //抛出错误处理
        return Promise.reject(error)
    }
)

export default instance